<template>
  <div>
    <h2>用户添加借款信息</h2>
    <table class="table" border="1">
      <tr>
        <td>借款ID</td>
        <td>{{list. Bid }}</td>
      </tr>
      <tr>
        <td>借款名称</td>
        <td>{{list. Bname }}</td>
      </tr>
      <tr>
        <td>借款最高金额</td>
        <td>{{list. Max_money }}</td>
      </tr>
      <tr>
        <td>借款年限</td>
        <td>{{ list. B_year}}</td>
      </tr>
      <tr>
        <td>利息</td>
        <td>{{list.  BL_num}}%</td>
      </tr>
      <tr>
        <td>借款金额</td>
        <td><input type="text" v-model="state.UB_Money"></td>
      </tr>
      <tr>
        <td colspan="2"><input type="button" value="借款" @click="Add"></td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import router from '@/router';
import axios from 'axios';
import { reactive, toRefs, onMounted } from 'vue';
import {useRoute} from 'vue-router'
const route = useRoute();
import {useStore} from '../store/user'
const userstore =useStore();
let data=reactive({
  list:{},
  state:{
    UB_Money:"",
    Bid:route.query.id,
    Uid:userstore.userInfo.Uid
  }
})
let {list,state}=toRefs(data);
onMounted(()=>{
  getlist()
})
//反填
function getlist()
{
  axios({
    url: 'http://localhost:51322/api/Borrow/GetAddInfoLixi',
    method: 'get',
    params:{
      id:route.query.id
    }
  })
    .then((res) => {
      console.log(res);
      list.value = res.data.data[0];
    })
    .catch((err) => {
      console.log(err);
    });
}
function Add()
{
  axios({
    url: 'http://localhost:51322/api/Borrow/PostBorrowAdd',
    method: 'post',
    data:state.value
  })
    .then((res) => {
      console.log(res);
      if(res.data.data>0)
    {
      alert("借款成功");
      
    }
    else{
      alert("借款失败");
    }
    })
    .catch((err) => {
      console.log(err);
    });
}
</script>

<style scoped>

</style>